//
//  JaneAVManager.m
//  EPA
//
//  Created by lanou3g on 16/4/21.
//  Copyright © 2016年 张静. All rights reserved.
//

#import "JaneAVManager.h"

@interface JaneAVManager ()
@property (nonatomic,strong)AVPlayer *player;

@end
@implementation JaneAVManager

//单例
+ (instancetype)shareManager {
    static JaneAVManager *manager = nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        if (manager == nil) {
            manager = [JaneAVManager new];
            manager.player = [[AVPlayer alloc]init];
        }
    });
    return manager;
}

//播放
- (void)play {
    AVPlayerItem *item = self.itemArray[self.currentIndex];
    [self.player replaceCurrentItemWithPlayerItem:item];
    [self.player play];
}
//暂停
- (void)pause {
    [self.player pause];
}
//跳转进度
- (void)seekToTime:(CMTime)time {
    [self.player seekToTime:time];
    [self.player play];
}
//上一曲
- (void)previous {
    self.currentIndex --;
    if (self.currentIndex < 0) {
        self.currentIndex = self.itemArray.count - 1;
    }
    [self play];
}
//下一曲
- (void)next {
    self.currentIndex ++;
    if (self.currentIndex >= self.itemArray.count) {
        self.currentIndex = 0;
    }
    [self play];
}

@end
